﻿#include "Utils.h"
#include <sstream>
#include <stdlib.h>
#include <time.h>
#include "cocos2d.h"
#include "../DevInclude.h"
#include "dictData.h"
#include <stdio.h>

USING_NS_CC;


int getMax(int p1, int p2){
    if(p1>p2){
        return p1;
    }
    return p2;
}

int getMin(int p1, int p2){
    if(p1<p2){
        return p1;
    }
    return p2;
}
int parseInt(string str){ 
    
    return parseInt(str.c_str());
}

int parseInt(const char* str){
    if(str==NULL){
        return 0;
    }
    
    return atof(str);
}


int HexToDec(const char *s)
{
	const char *p = s;
    
	//空串返回0。
	if(*p == '\0')
		return 0;
	
	//忽略开头的'0'字符
	while(*p == '0')
		p++;
    
	int dec = 0;
	char c;
    
	//循环直到字符串结束。
	while(c = *p++)
	{
		//dec乘16
		dec <<= 4;
		
		//数字字符。
		if(c >= '0' && c <= '9')
		{
			dec += c - '0';
			continue;
		}
        
		//小写abcdef。
		if(c >= 'a' && c <= 'f')
		{
			dec += c - 'a' + 10;
			continue;
		}
        
		//大写ABCDEF。
		if(c >= 'A' && c <= 'F')
		{
			dec += c - 'A' + 10;
			continue;
		}
        
		//没有从任何一个if语句中结束，说明遇到了非法字符。
		return -1;
	}
    
	//正常结束循环，返回10进制整数值。
	return dec;
}

double parseDouble(const char* str){
    if(str==NULL){
        return 0;
    }
    
    return atof(str);
}
float parseNumber(const char* str){
    if(str==NULL){
        return 0;
    }
    
    return atof(str);
}
 
time_t getUnixTime(){
    time_t rawTime;
	time(&rawTime);
	return rawTime;
}

long getTimer()
{
    struct cc_timeval now;
    CCTime::gettimeofdayCocos2d(&now, NULL);
    long a=now.tv_sec%100000;
    return (a * 1000 + now.tv_usec / 1000);
   // return (now.tv_sec * 1000 + now.tv_usec * 0.001f);
 
}
 

string parseString(long i){
    string c;
    
    ostringstream oss;
    oss<<i;
    c=oss.str();
    return c;
}


string parseString(int i){
    string c;
    
    ostringstream oss;
    oss<<i;
    c=oss.str();
    return c;
}
 
string  parseString(float i){
    string c;
    
    ostringstream oss;
    oss<<i;
    c=oss.str();
    return c;
}


string  parseString2(int n){
    string ret;
    if(n<10){
        ret= "0"+parseString(n) ;
    }else {
        ret= parseString(n) ;
        
    }
    return ret;
    
}


static int  randIdx=0;

int getRandom(int start,int end){
    srand (getTimer()+randIdx);
    randIdx++;
    return (start)+(rand()%(end-start+1));
    
}



void splitStr(vector<string> &gRet, string cStr ,const char* cSplit ){
    gRet.clear();
    int comma_n = 0;
	do
	{
		string tmp_s = "";
		comma_n = cStr.find( cSplit );
		if( -1 == comma_n )
		{
			tmp_s = cStr.substr( 0, cStr.length() );
			gRet.push_back( tmp_s );
			break;
		}
		tmp_s = cStr.substr( 0, comma_n );
		cStr.erase( 0, comma_n+1 );
		gRet.push_back( tmp_s );
	} 
	while(true);
}



void parseFilePath(const char * pszIn, char * pszOut)
{
	if(!pszIn || !pszOut)
		return;

	int i;
	int nInLen = 0;
	bool bFind = false;
	while (*(pszIn+nInLen) != '\0') ++nInLen;

/*#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
	for (i = nInLen; i > 0; --i)
	{
		if(*(pszIn+i) == '/')
		{
			bFind = true;
			break;
		}
	}
#else*/
	for (i = 0; i < nInLen; ++i)
	{
		if(*(pszIn+i) == '/')
		{
			
            if(i==0){
                bFind = true;
            }
			break;
		}
	}
//#endif

	if(bFind)
		memcpy(pszOut, pszIn+i+1, nInLen-i-1);
	else
		memcpy(pszOut, pszIn, nInLen);
}

std::string parseFilePath(const char * pszIn)
{
	if(!pszIn)
		return "";

	int i;
	bool bFind = false;
	int nInLen = 0;
	while (*(pszIn+nInLen) != '\0') ++nInLen;
    
/*#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    for (i = nInLen; i > 0; --i)
	{
		if(*(pszIn+i) == '/')
		{
			bFind = true;
			break;
		}
	}
#else
   */
	for (i = 0; i < nInLen; ++i)
	{
		if(*(pszIn+i) == '/')
		{
            if(i==0){
                
                bFind = true;
            }
			break;
		}
	}
//#endif

	if(bFind)
		return string(pszIn+i+1);

	return string(pszIn);
}

string readToken(const string & strText, const char * tagStart, const char * tagEnd)
{
	if(!tagStart || !tagEnd)
		return "";

	int nStart = strText.find(tagStart);
	int nEnd = strText.find(tagEnd);
	if(-1 != nStart && -1 != nEnd)
	{
		nStart += strlen(tagStart);
		return strText.substr(nStart, nEnd-nStart);
	}

	return "";
}

//target上的点相对于屏幕里面的点
CCPoint getPosInScreen(CCPoint point,CCNode* pTarget){
     
   
    return pTarget->convertToWorldSpace(point);
}


//屏幕上的点相对于target里面的点
CCPoint  getPosInTarget(CCPoint point,CCNode* pTarget){
     
    
     return pTarget->convertToNodeSpace(point);
      
    
}


void TraceInt(int nNum){
    
    
    Trace(parseString(nNum).c_str());
}


void  TracePoint(CCPoint pos){
    
    
    Trace(("x="+parseString(pos.x) +" y="+parseString(pos.y)) .c_str());
}
 

void Trace(const char * pszFormat, ...){
    
    CCLog(pszFormat); 
}

int readInt(xml_node<> * pItem,const char* cAttr)
{
	if(!cAttr)
		return 0;

	xml_node<> * pNode = pItem->first_node(cAttr);
	if(!pNode)
		return 0;
    
	char * v = pNode->value();
	if(v)
		return atoi(v);
	else
		return 0;
}


float readFloat(xml_node<> * pItem,const char* cAttr)
{
	if(!cAttr)
		return 0;

	xml_node<> * pNode = pItem->first_node(cAttr);
	if(!pNode)
		return 0;

	char * v = pNode->value();
	if(v)
		return atof(v);
	else
		return 0;
}

 
void readString(xml_node<> * pItem,const char* cAttr, string & ret)
{
	ret = "";
	if(!cAttr)
		return;
    
    
	xml_node<> * pNode = pItem->first_node(cAttr);
    

	if(!pNode)
		return;
    
    
    xml_node<> * cdata = pNode->first_node();
    if (cdata && cdata->type() == rapidxml::node_cdata)
    {
        ret= cdata->value();
        
    }
     

	char * v = pNode->value();
	if(v)
		ret.append(v);
}

void readDate(xml_node<> * pItem, const char * pszAttr, tm & pTm)
{
	memset(&pTm, 0, sizeof(tm));

	if(!pszAttr)
		return;

	xml_node<> * pNode = pItem->first_node(pszAttr);
	if(!pNode)
		return;

	int nData[6] = {0};
	char szBuf[12] = {0}; 

	int nIdx = 0;
	int nBufIdx = 0;
	const char * pszTemp = pNode->value();
	while(*pszTemp != '\0')
	{
		if(*pszTemp == ' ' || *pszTemp == '-' || *pszTemp == ':')
		{
			nData[nIdx] = atoi(szBuf);
			nBufIdx = 0;
			++nIdx;
			++pszTemp;
			memset(szBuf, 0, 12);
			continue;
		}

		szBuf[nBufIdx++] = *(pszTemp++);
	}

	nData[nIdx] = atoi(szBuf);
	pTm.tm_year = nData[0];
	pTm.tm_mon = nData[1];
	pTm.tm_mday = nData[2];
	pTm.tm_hour = nData[3];
	pTm.tm_min = nData[4];
	pTm.tm_sec = nData[5];
}

int readIntArr(xml_node<> * pItem, const char * pszAttr, int * pArr, const char szSplit)
{
	if(!pszAttr || !pArr)
		return 0;

	xml_node<> * pNode = pItem->first_node(pszAttr);
	if(!pNode)
		return 0;

	int nCnt = 0;
	int nIdx = 0;
	int nBufIdx = 0;
	char szBuf[32] = {0}; 

	const char * pszTemp = pNode->value();
	if(!pszTemp)
		return 0;
    
    char szSplits[4] = {0};
    sprintf(szSplits, "%c",szSplit );

     
	while(*pszTemp != '\0')
	{
		if(*pszTemp == szSplit)
		{
			if(strcmp(szBuf, szSplits))
			{
				*(pArr+nIdx) = atoi(szBuf);
				++nCnt;
			}

			nBufIdx = 0;
			++nIdx;
			++pszTemp;
			memset(szBuf, 0, 32);
			continue;
		}

		szBuf[nBufIdx++] = *(pszTemp++);
	}

	if(strlen(szBuf) && strcmp(szBuf, szSplits))
	{
		*(pArr+nIdx) = atoi(szBuf);
		++nCnt;
	}

	return nCnt;
}

void readIntArr(xml_node<> * pItem, const char * pszAttr, int ** pArr, int n1, const char szSplit, const char szSubSplit)
{
	if(!pszAttr || !pArr)
		return;

	xml_node<> * pNode = pItem->first_node(pszAttr);
	if(!pNode)
		return;

	char szBuf[32] = {0};
	int nIdx = 0;			// 一维索引
	int nIdx1 = 0;			// 二维索引
	int nBufIdx = 0;

	const char * pszTemp = pNode->value();
	while(*pszTemp != '\0')
	{
		if(*pszTemp == szSubSplit)
		{
			*((int*)pArr+nIdx*n1+nIdx1) = atoi(szBuf);
			nBufIdx = 0;
			++nIdx1;
			++pszTemp;
			memset(szBuf, 0, 32);
			continue;
		}

		if(*pszTemp == szSplit)
		{
			*((int*)pArr+nIdx*n1+nIdx1) = atoi(szBuf);
			nBufIdx = 0;
			++nIdx;
			++pszTemp;
			nIdx1 = 0;
			memset(szBuf, 0, 32);
			continue;
		}

		szBuf[nBufIdx++] = *(pszTemp++);
	}

	*((int*)pArr+nIdx*n1+nIdx1) = atoi(szBuf);
}

int utf8ToUnicode(const char * pIn, wchar_t * pOut)
{
	if(!pIn || !pOut)		// 无数据源直接返回成功
		return 0;

	int retval = 0;
	const UTF8 * pInSrc = reinterpret_cast<const UTF8*>(pIn);
	int nLen = strlen(pIn) + 1;
	
	if(sizeof(wchar_t) == sizeof(UTF32)) 
	{
		UTF32 * pUtf32 = (UTF32 *)pOut;
		retval = (int)ConvertUTF8toUTF32(&pInSrc, pInSrc + nLen, &pUtf32, pUtf32 + nLen, lenientConversion);
	}
	else if(sizeof(wchar_t) == sizeof(UTF16)) 
	{
		UTF16 * pUtf16 = (UTF16 *)pOut;
		retval = (int)ConvertUTF8toUTF16(&pInSrc, pInSrc + nLen, &pUtf16, pUtf16 + nLen, lenientConversion);
	}

	if((int)conversionOK != retval)	// 转换失败
		retval = -1;
	
	return retval;
}

int unicodeToUtf8(const wchar_t * pIn, char * pOut)
{
	if(!pIn || !pOut)		// 无数据源直接返回成功
		return 0;

	int retval = 0;
	size_t uInputLen = wcslen(pIn) + 1;

    UTF8 * pUtf8 = (UTF8 *)pOut;
    if(sizeof(wchar_t) == sizeof(UTF32))
	{
        const UTF32 * pUtf32 = (const UTF32 *)pIn;
        retval = ConvertUTF32toUTF8(&pUtf32, pUtf32 + uInputLen, &pUtf8, pUtf8 + 2*uInputLen+1, lenientConversion);
    }
    else if(sizeof(wchar_t) == sizeof(UTF16))
	{
        const UTF16 * pUtf16 = (const UTF16 *)pIn;
        retval = ConvertUTF16toUTF8(&pUtf16, pUtf16 + uInputLen, &pUtf8, pUtf8 + 2*uInputLen+1, lenientConversion);
    }
    
	if((int)conversionOK != retval)	// 转换失败
		retval = -1;

	return retval;
}



int parseMapY(int y){
    int height=  CCDirector::sharedDirector()->getWinSize().height;
    
    return height-y;
    
}



void parseMapPos(int x,int y,CCPoint& pos){
     
     pos.x = x * DEFAULT_GRIDWIDTH +(- (y % 2) +1)* DEFAULT_GRIDWIDTH * 0.5  ;
     pos.y= y * DEFAULT_GRIDHEIGHT * 0.5;
     
}

CCPoint parseMapPos(int x,int y){
    
    int retX;
    int retY;
    retX = x * DEFAULT_GRIDWIDTH +(- (y % 2) +1)* DEFAULT_GRIDWIDTH * 0.5  ;
    retY= y * DEFAULT_GRIDHEIGHT * 0.5;
    
    return ccp(retX,retY);
}


void interpolate(CCPoint& p1, CCPoint& p2,float param,CCPoint& result){
    result.x=p2.x+ (p1.x-p2.x)*param;
    result.y=p2.y+ (p1.y-p2.y)*param;
}


 
void replaceStr(string& str ,const char* find ,const char* replace){
    string searchString( find);
    string replaceString( replace );
    
    if(find==replace){
        return ;
    }
    
    string::size_type pos = 0;
    while ( (pos = str.find(searchString, pos)) != string::npos ) {
        str.replace( pos, searchString.size(), replaceString );
        pos++;
    }
}


float getAngle(const CCPoint& p1,const CCPoint& p2)
{
    float angle=0;
    
    
    float dis =  sqrtf((p2.x - p1.x) * (p2.x - p1.x) + (p2.y - p1.y) * (p2.y - p1.y)); 
    float cosQ = ((p2.x - p1.x)*1.0f) / dis;
    int sign = p2.y < p1.y ? -1 : 1;
    angle = sign * acosf(cosQ);
    return angle * 180 / PI;
}


ccColor3B parseRgb(int hex) 
{
    ccColor3B color;
    color.r=( 0xff <<16 & hex ) >> 16;
    color.g=( 0xff <<8 & hex ) >> 8;
    color.b=0xff & hex;
    return color;
}


int parseH(const ccColor3B& color){
    return color.r<< 16 | color.g << 8 | color.b;
}


CCRenderTexture* createStroke(CCSprite* label, int size, ccColor3B color, GLubyte opacity){
    CCRenderTexture* rt = CCRenderTexture::create(
                                                                            label->getTexture()->getContentSize().width + size * 2,
                                                                              label->getTexture()->getContentSize().height+size * 2
                                                                            );
  
    CCPoint originalPos = label->getPosition();
    ccColor3B originalColor = label->getColor();
    GLubyte originalOpacity = label->getOpacity();
    bool originalVisibility = label->isVisible();
    label->setColor(color);
    label->setOpacity(opacity);
    label->setVisible(true);
    ccBlendFunc originalBlend = label->getBlendFunc();
    ccBlendFunc bf = {GL_SRC_ALPHA, GL_ONE};
    label->setBlendFunc(bf);
    CCPoint bottomLeft = ccp(
                             label->getTexture()->getContentSize().width * label->getAnchorPoint().x + size,
                                label->getTexture()->getContentSize().height * label->getAnchorPoint().y + size);
   /* CCPoint positionOffset= ccp(   - label->getTexture()->getContentSize().width / 2,
                                    - label->getTexture()->getContentSize().height / 2);
  */
    rt->begin();
    for (int i=0; i<360; i+= 45) // you should optimize that for your needs
    {
        label->setPosition(
                           ccp(bottomLeft.x + sin(CC_DEGREES_TO_RADIANS(i))*size, bottomLeft.y + cos(CC_DEGREES_TO_RADIANS(i))*size)
                            );
         label->visit();
    }
    rt->end();
    label->setPosition(originalPos);
    label->setColor(originalColor);
    label->setBlendFunc(originalBlend);
    label->setVisible(originalVisibility);
    label->setOpacity(originalOpacity); 
    rt->setPosition(label->getPosition());
    rt->setAnchorPoint(label->getAnchorPoint()); 
    return rt;
 
}



char *  strrevX (char * str)
{
	char *start = str;
	char *left = str;
	char ch;

	while (*str++)                 /* find end of string */
		;
	str -= 2;

	while (left < str)
	{
		ch = *left;
		*left++ = *str;
		*str-- = ch;
	}

	return(start);
}

char* rtrim(char* str)
{
	int n = strlen(str)-1;
	while(n>0)
	{
		if(*(str+n)==' ')
		{
			*(str+n)= '\0';
			n--;
		}
		else
		{
			break;
		}
	}
	return str;
}

char *ltrim(char* str)
{
	strrevX(str);
	rtrim(str);   //调用上面的rtrim()函数
	strrevX(str);
	return str;
}

char* trim(char* str)
{
	return rtrim(ltrim(str));
}

std::string& trimstr(std::string &s) 
{ 
	if (s.empty()) 
	{ 
		return s; 
	} 
	s.erase(0,s.find_first_not_of(" ")); 
	s.erase(s.find_last_not_of(" ") + 1); 
	return s; 
} 

std::string& remove_char(std::string& str, char ch)
{
	string::iterator new_end = remove_if(str.begin(), str.end(), bind2nd(equal_to<char>(), ch));
	str.erase(new_end, str.end());
	return str;
}

std::string&  replace_all_distinct(std::string&   str,const   std::string&   old_value,const   std::string&   new_value)   
{   
	for(std::string::size_type  pos(0);  pos!=std::string::npos; pos+=new_value.length())   
	{   
		if((pos=str.find(old_value,pos))!=std::string::npos)  
			str.replace(pos,old_value.length(),new_value);
		else
			break;   
	}   

	return  str;   
} 

template<class T> T parseStringX(const std::string& str) 
{
	T value;
	std::istringstream iss(str);
	iss >> value;
	return value;
}

template<class T> std::string toString(const T& value) 
{
	std::ostringstream oss;
	oss << value;
	return oss.str();
}

 
///////////////////////////////////////////////////
std::string numToFixedString(uint32 num, int len)
{
	std::string str = toString(num);
	while (str.length() < (unsigned int)len)
	{
		str = "0" + str;
	}
	return str;
}

std::string numToMoneyString(uint32 num)
{
	int n= 0;
	while(num!=0)
	{
		n++;
		num = num/10;
	}	// 位数
	int p = (n - 1) / 3;	 // 逗号数

	std::string str;
	for (int i= 0; i < p; ++i)
	{
		str = "," + numToFixedString(num % 1000, 3) + str;
		num = num / 1000;
	}

	str = toString(num);
	return str;
}

int	moneyStringToNum(std::string str)
{
	str = trimstr(str);
	remove_char(str, ',');// 去掉逗号
	int num =  parseStringX<int>(str); 
	return num;
}


string parseTime(int num){
    if(num<0) num=0;
    
    int hour=num/(60*60);
    int min=(num%3600)/60;
    int sec=num%60;
    
    string ret= parseString2(hour)+":";
    ret.append(parseString2(min)+":");
    ret.append(parseString2(sec));
    return ret;
}

//
//#ifdef WIN32
//bool IConvConvert(const char *from_charset, const char *to_charset, const char *inbuf, int inlen, char *outbuf, int outlen) 
//{
//
//	iconv_t cd = iconv_open(to_charset, from_charset);
//
//	if (cd == 0) return false;
//
//	const char **pin = &inbuf;
//
//	char **pout = &outbuf;
//
//	memset(outbuf,0,outlen);
//
//	size_t ret = iconv(cd,pin,(size_t *)&inlen,pout,(size_t *)&outlen);
//
//	iconv_close(cd);
//
//	return ret == (size_t)(-1) ? false : true;
//
//}
//#endif
//
//const char* GBKToUTF8(const char* input)
//{
//#ifdef WIN32
//	char textOut[1024];
//	bool ret = IConvConvert("gb2312", "utf-8", input, strlen(input),textOut, 1024);
//	if(ret) {
//		char* out = new char(strlen(textOut) + 1);
//		memcpy(out, textOut, strlen(textOut));
//		return out;
//	} else {
//		return input;
//	}
//#else
//	return input;
//#endif
//}
//
//const char* UTF8ToGBK(const char* input)
//{
//#ifdef WIN32
//	char textOut[1024];
//	bool ret = IConvConvert("utf-8", "gb2312", input, strlen(input), textOut, 1024);
//	if(ret) {
//		char* out = new char(strlen(textOut) + 1);
//		memcpy(out, textOut, strlen(textOut) + 1);
//		return out;
//	} else {
//		return input;
//	}
//#else
//	return input;
//#endif
//}

std::string getDictValue( const char* key )
{
	return DictData::shareConfData()->getValue(key);
}

#define kBufferMaxLen (1024*10)
std::string getDictParamValue( const char* key, ... )
{
	string format = getDictValue(key);
	string result;
	va_list ap;
	va_start(ap, key);
	char* pBuf = (char*)malloc(kBufferMaxLen);
	if (pBuf != NULL)
	{
		vsnprintf(pBuf, kBufferMaxLen, format.c_str(), ap);
		result = pBuf;
		free(pBuf);
	}
	va_end(ap);

	return result;
}


static unsigned char utf8_look_for_table[] = 
{
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
	2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
	3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
	4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 1, 1
};

#define UTFLEN(x)  utf8_look_for_table[(x)]

//计算str字符数目
int getUtf8Length(const char *str)
{
	int clen = strlen(str);
	int len = 0;
	char* tempChar = new char[clen + 1];
	memcpy(tempChar, str, clen);
	tempChar[clen] = '\0';

	for(char *ptr = tempChar; 
		*ptr!=0&&len<clen; 
		len++, ptr+=UTFLEN((unsigned char)*ptr));

	delete[] tempChar;
	return len;
}

//get子串
char* subUtfString(char *str, unsigned int start, unsigned int end)
{
	int len = getUtf8Length(str);

	if(start >= len) return NULL;
	if(end > len) end = len;

	char *sptr = str;
	for(int i = 0; i < start; ++i,sptr+=UTFLEN((unsigned char)*sptr));

	char *eptr = sptr;
	for(int i = start; i < end; ++i,eptr += UTFLEN((unsigned char)*eptr));

	int retLen = eptr - sptr;
	char *retStr = (char*)malloc(retLen+1);
	memcpy(retStr, sptr, retLen);
	retStr[retLen] = 0;
	return retStr;
}


string getTimeStr(long long time){
    
    time_t  curTime=time;
    struct tm *date;
    date = localtime(&curTime);
    string ret= parseString2(date->tm_hour);
    ret.append(":"+parseString2(date->tm_min));
    return ret;
}

